<?php 

//Redirect all categories with only 1 post directly to the post, skipping the archive pge
global $wp_query;
if (function_exists('gis_redirect_to_post') ) {
	add_action( 'template_redirect', 'gis_redirect_to_post' );
}
//if category is staff, it does not redirect
function gis_redirect_to_post() {
	global $wp_query;
		
	if ( is_archive () && $wp_query->post_count == 1 && !is_category( 'staff' ) ) {
		the_post();
		$post_url = get_permalink();
		wp_redirect( $post_url );
	}
}
	
if (function_exists('register_nav_menus')) {
register_nav_menus( array(
	'primary' => __( 'Top Menu', 'proudthemes' ),
    'secondary' => __( 'Bottom Menu', 'proudthemes' ),
	) );
}

if (function_exists('add_custom_background')) {
 add_custom_background();
}

add_theme_support( 'post-thumbnails' );

if (is_admin() && $_GET['activated'] == 'true') {
	header("Location: admin.php?page=proud_options");
}

if (is_admin() && $_GET['page'] == 'proud_options') {
	add_action('admin_head', 'proud_admin_css');
	// wp_enqueue_script('jquery');
	wp_enqueue_script('jorascript', get_bloginfo('template_directory').'/admin/scripts/easytabs.js');
}

function proud_admin_css() {
	echo '
	<link rel="stylesheet" type="text/css" media="screen" href="'.get_bloginfo('template_directory').'/admin/css/tabs.css" />
	';
}

function csv_tags() {
	$posttags = get_the_tags();
	foreach((array)$posttags as $tag) {
		$csv_tags .= $tag->name . ',';
	}
	echo '<meta name="keywords" content="'.$csv_tags.'" />';
}


/* 
Plugin Name: Ping/Track/Comment Count 
Plugin URI: http://txfx.net/code/wordpress/ping-track-comment-count/ 
Version: 1.1 
Description: Provides functions that return or display the number of trackbacks, pingbacks, comments or combined pings recieved by a given post.  Other authors: Chris J. Davis, Scott "Skippy" Merrill 
Author: Mark Jaquith 
Author URI: http://markjaquith.com/ 

This program is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation; either version 2 
of the License, or (at your option) any later version. 

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the 
GNU General Public License for more details. 

You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software 
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA     02110-1301, USA. 

*/
function get_comment_type_count($type='all', $post_id = 0) { 
    global $cjd_comment_count_cache, $id, $post; 
    if ( !$post_id ) 
        $post_id = $post->ID; 
    if ( !$post_id ) 
        return; 

    if ( !isset($cjd_comment_count_cache[$post_id]) ) { 
        $p = get_post($post_id); 
        $p = array($p); 
        update_comment_type_cache($p); 
    } 

    if ( $type == 'pingback' || $type == 'trackback' || $type == 'comment' ) 
        return $cjd_comment_count_cache[$post_id][$type]; 
    elseif ( $type == 'ping' ) 
        return $cjd_comment_count_cache[$post_id]['pingback'] + $cjd_comment_count_cache[$post_id]['trackback']; 
    else 
        return array_sum((array) $cjd_comment_count_cache[$post_id]); 

} 

function comment_type_count($type = 'all', $post_id = 0) { 
        echo get_comment_type_count($type, $post_id); 
} 

function update_comment_type_cache($queried_posts) { 
    global $cjd_comment_count_cache, $wpdb; 

    if ( !$queried_posts ) 
        return $queried_posts; 


    foreach ( (array) $queried_posts as $post ) 
        if ( !isset($cjd_comment_count_cache[$post->ID]) ) 
            $post_id_list[] = $post->ID; 

    if ( $post_id_list ) { 
        $post_id_list = implode(',', $post_id_list); 

        foreach ( array('', 'pingback', 'trackback') as $type ) { 
            $counts = $wpdb->get_results("SELECT ID, COUNT( comment_ID ) AS ccount 
            FROM $wpdb->posts 
            LEFT JOIN $wpdb->comments ON ( comment_post_ID = ID AND comment_approved = '1' AND comment_type='$type' ) 
            WHERE post_status = 'publish' AND ID IN ($post_id_list) 
            GROUP BY ID"); 

            if ( $counts ) { 
                if ( '' == $type ) 
                    $type = 'comment'; 
                foreach ( $counts as $count ) 
                    $cjd_comment_count_cache[$count->ID][$type] = $count->ccount; 
            } 
        } 
    } 
    return $queried_posts; 
} 
add_filter('the_posts', 'update_comment_type_cache');

/*
Plugin Name: Limit Posts
Plugin URI: http://labitacora.net/comunBlog/limit-post.phps
Description: Limits the displayed text length on the index page entries and generates a link to a page to read the full content if its bigger than the selected maximum length.
Usage: the_content_limit($max_charaters, $more_link)
Version: 1.1
Author: Alfonso Sanchez-Paus Diaz y Julian Simon de Castro
Author URI: http://labitacora.net/
License: GPL
Download URL: http://labitacora.net/comunBlog/limit-post.phps
Make:
    In file index.php
    replace the_content()
    with the_content_limit(1000, "more")
*/

function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = strip_tags($content);

   if (strlen($_GET['p']) > 0 && $thisshouldnotapply) {
      echo $content;
   }
   else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content;
        echo $content;
        echo "...";
   }
   else {
      echo $content;
   }
}

function catch_that_image ($post_id=0, $width=60, $height=60, $img_script='') {
	global $wpdb;
	if($post_id > 0) {

		 // select the post content from the db

		 $sql = 'SELECT post_content FROM ' . $wpdb->posts . ' WHERE id = ' . $wpdb->escape($post_id);
		 $row = $wpdb->get_row($sql);
		 $the_content = $row->post_content;
		 if(strlen($the_content)) {

			  // use regex to find the src of the image

			preg_match("/<img src\=('|\")(.*)('|\") .*( |)\/>/", $the_content, $matches);
			if(!$matches) {
				preg_match("/<img class\=\".*\" title\=\".*\" src\=('|\")(.*)('|\") .*( |)\/>/U", $the_content, $matches);
			}
			
			$the_image = '';
			$the_image_src = $matches[2];
			$frags = preg_split("/(\"|')/", $the_image_src);
			if(count($frags)) {
				$the_image_src = $frags[0];
			}

			  // if src found, then create a new img tag

			  if(strlen($the_image_src)) {
				   if(strlen($img_script)) {

					    // if the src starts with http/https, then strip out server name

					    if(preg_match("/^(http(|s):\/\/)/", $the_image_src)) {
						     $the_image_src = preg_replace("/^(http(|s):\/\/)/", '', $the_image_src);
						     $frags = split("\/", $the_image_src);
						     array_shift($frags);
						     $the_image_src = '/' . join("/", $frags);
					    }
					    $the_image = '<img alt="" src="' . $img_script . $the_image_src . '" />';
				   }
				   else {
					    $the_image = '<img alt="" src="' . $the_image_src . '" width="' . $width . '" height="' . $height . '" />';
				   }
			  }
			  return $the_image_src;
		 }
	}
}

if ( function_exists('register_sidebar') )

register_sidebar(array('name'=>'Sidebar: Homepage (Left)',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));

register_sidebar(array('name'=>'Sidebar: Homepage (Right)',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));

register_sidebar(array('name'=>'Sidebar: Homepage (Middle)',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));

register_sidebar(array('name'=>'Sidebar: Archive Pages',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));

register_sidebar(array('name'=>'Sidebar: Pages (Left)',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));

register_sidebar(array('name'=>'Sidebar: Pages (Right)',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));

register_sidebar(array('name'=>'Sidebar: Posts (Left)',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));

register_sidebar(array('name'=>'Sidebar: Posts (Right)',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));

register_sidebar(array('name'=>'Footer: Right',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<p class="heading">',
'after_title' => '</p>',
));


class Unlink_Walker extends Walker_Category {
 
	function start_el(&$output, $category, $depth, $args) {
		extract($args);
		
		$cat_name = esc_attr( $category->name );
		$cat_name = apply_filters( 'list_cats', $cat_name, $category );
		$cat_ID = esc_attr( $category->cat_ID );
		$children = (array_filter(explode(',',get_category_children($cat_ID, false ,','))));
		$haschildren = (count($children));
		$cat_parent = $category->parent;
		
		
		if (($haschildren == 0) || ($cat_parent != '0')){
		$link = '<a href="' . esc_attr( get_term_link($category) ) . '" ';
		}
		else 	
		$link = '<a class="unlink"';
		
		if ( $use_desc_for_title == 0 || empty($category->description)) {
			if ($cat_parent != '0' )
				$link .= 'title="' . esc_attr( sprintf(__( $cat_name ), $cat_id) ) . '"';
			else 
				$link .= 'title="' . esc_attr( sprintf(__( $cat_name ), $cat_id) ) . '"';
		}
		else
			$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
		$link .= '>';
		$link .= $cat_name . '</a>';

		if ( !empty($feed_image) || !empty($feed) ) {
			$link .= ' ';

			if ( empty($feed_image) )
				$link .= '(';

			$link .= '<a href="' . get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) . '"';

			if ( empty($feed) ) {
				$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
			} else {
				$title = ' title="' . $feed . '"';
				$alt = ' alt="' . $feed . '"';
				$name = $feed;
				$link .= $title;
			}

			$link .= '>';

			if ( empty($feed_image) )
				$link .= $name;
			else
				$link .= "<img src='$feed_image'$alt$title" . ' />';

			$link .= '</a>';

			if ( empty($feed_image) )
				$link .= ')';
		}

		if ( !empty($show_count) )
			$link .= ' (' . intval($category->count) . ')';

		if ( !empty($show_date) )
			$link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);

		if ( 'list' == $args['style'] ) {
			$output .= "\t<li";
			$class = 'cat-item cat-item-' . $category->term_id;
			if ( !empty($current_category) ) {
				$_current_category = get_term( $current_category, $category->taxonomy );
				if ( $category->term_id == $current_category )
					$class .=  ' current-cat';
				elseif ( $category->term_id == $_current_category->parent )
					$class .=  ' current-cat-parent';
			}
			$output .=  ' class="' . $class . '"';
			$output .= ">$link\n";
		} else {
			$output .= "\t$link<br />\n";
		}
	}

}



//lists all non-empty subcategories categories under main category
//posts appear under current subcategory, click on subcategory leads to archive of those posts
function list_cat_posts_all() {

	$currCat = get_the_category();
	$currCatID = $currCat[0]->cat_ID;
		
		if (isset($_GET['certclass'])) { 
			$parentid = '9'; 
		} else {
			$parentid = $currCat[0]->parent;
		}
		
		global $post;
		$currpostid = $post->ID;
		$hide_empty = true;
		$hierarchical = true;
		
		$args = array(
			'hide_empty' => $hide_empty,
			'hierarchical' => $hierarchical,
			'parent' => $parentid,
			);
			
		$catarray = get_categories($args);
		foreach ($catarray as $category) {
			$catid = $category->term_id;
			$link = get_category_link($catid);

			$order_alphabetically = array( 'Finding Guides', 'Classes' );
			
			if ( in_array( $category->name, $order_alphabetically ) ) { 
				//if category is collection highlights or classes,  order posts alphabetically 
				$myquery = new WP_Query(array('category__in' => array($catid), 'orderby' => 'title', 'order' => 'ASC',));
			} else {
				//if category is not listed above, order posts by custom order
				$myquery = new WP_Query(array('category__in' => array($catid), 'orderby' => 'menu_order', 'order' => 'ASC',));
		}
				
		if (!$hide_empty || $hierarchical)  {
			echo "
				<ul class='menuleft'>
				<li"; 
				
			//if certclass variable is NOT set, find current category
			//and add class 'current' so we know which page we're on
			if ($currCatID == $catid && !isset($_GET['certclass']) ) { 
				echo " class='current-cat'"; 
			} 
			
			//if certclass variable is set, set certificate classes(10)
			//as the current category
			if ( isset($_GET['certclass']) && $category->name == 'Graduate Certificate' ) { echo " class='current-cat'"; } 
			
				echo "><h2><a href='$link' title='$category->name' >$category->name</a></h2></li>";
		}

		if ($myquery->have_posts()) : 
			if ($hide_empty && !$hierarchical ) { 
				echo "
					<li><a href='$link' title='$category->name' >$category->name</a></li>
				";
			}
			
			echo "<ul class='current-cat-children'>";
					
			if (!isset($_GET['certclass'])) {
				while ($myquery->have_posts()) : $myquery->the_post();
					if ($myquery->post_count !== 1 && $currCatID == $catid) {
						echo "<li"; 
						if ( is_single() && $currpostid == $myquery->post->ID ) { 
							echo " class='current-post'"; 
						} ?>
						>
                        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
			  <?php } 
					wp_reset_postdata(); 
				endwhile;
			}

			if ( isset( $_GET['certclass'] ) ) {
				$exception = new WP_Query( array( 'category__in' => array('10'), 'orderby' => 'menu_order', 'order' => 'ASC' ) );
				while ( $exception->have_posts() ) : $exception->the_post();
					if ( $category->name == 'Graduate Certificate' ) { 
						echo "<li"; 
						if ( get_the_title() == 'Certificate Classes' ) { 
							echo " class='current-post'"; 
						} ?>
						>
                        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
			  <?php }  
					wp_reset_postdata(); 
				endwhile;
			}
			echo "
				</ul><!--.children-->
				</ul><!--.category-->
			";
		
			else:
			if (!$hide_empty || $hierarchical) 
				echo '<p> &nbsp;&nbsp;&nbsp;- None Found -</p>';
		endif;
	}				

}



//use to check if URL entered into magic field is valid before linking to it (eg. link to syllabus)
//used in single-classes.php & in single-collection-highlights.php
//returns true or false, so can be used as condition
function url_exists($url) {
    // Version 4.x supported
    $handle   = curl_init($url);
    if (false === $handle)
    {
        return false;
    }
    curl_setopt($handle, CURLOPT_HEADER, false);
    curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works
    curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox    
    curl_setopt($handle, CURLOPT_NOBODY, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
    $connectable = curl_exec($handle);
    curl_close($handle); 
    return $connectable;
}

//use to check if array of URLs are broken
//returns broken urls in array
//returns true or false, so can be used as condition
function broken_urls($url) {
    // Version 4.x supported
    $handle   = curl_init($url);
    if (false === $handle)
    {
        return $url;
    }
    curl_setopt($handle, CURLOPT_HEADER, false);
    curl_setopt($handle, CURLOPT_FAILONERROR, true);  // this works
    curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox    
    curl_setopt($handle, CURLOPT_NOBODY, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
    $connectable = curl_exec($handle);
    curl_close($handle); 
    
    if ($connectable == false) {
    	return $url;
    }
}

//extracts the first occurence of a URL from a string
//returns URL
function extract_url($html) {
	if (preg_match('/href="([^"]*)"/i', $html , $regs))
	{
		$result = $regs[1];
	} 
	return $result;
}

//extracts all URLs from an html link 
//(ex, given "<a href='http://www.fiu.edu'></a>", returns "http://www.fiu.edu")
//returns array with urls
function extract_urls($string){
	preg_match_all('~href=("|\')(.*?)\1~i', $string, $out);
	return $out[2];
}
					
//make excerpt from custom field data
//mimics WP's the_excerpt()
function magic_excerpt($text, $ellipsis='[...]', $max_words = '55' ) {
		$content = apply_filters('the_excerpt', $text );
        $words = explode( ' ', $content );
        if ( count( $words ) > $max_words ) {
            $excerpt = implode( ' ', array_slice( $words, 0, $max_words ) ) ." ".$ellipsis;
        }
        else { $excerpt = str_replace('<p>&nbsp;</p>', "", $text);
        } 
    return $excerpt;
}

//magic fields multiline textbox adds an extra <p>&nbsp;</p> when there is any space after the last character of the field
//this function removes the empty p tags if they exist
//should be used whenever calling a magic fields multiline textbox field
function emptyP($string) {
	$result = str_replace('<p>&nbsp;</p>', "", $string);
	return $result;
}

if (!function_exists('has_children_cats')) {
	function has_children_cats( $cat_name ) {
		$cat_ID = get_cat_ID( $cat_name );
		$args = array ('child_of' => $cat_ID );
		$categories = get_categories( $args );
		if ( $categories ) {
			return true;
		}
		else {
	    	return false;
		}
	}
}

if (!function_exists('get_first_cat_link')) {
	function get_first_cat_link( $cat_name ) {
		$cat_ID = get_cat_ID( $cat_name );
		$args = array ('child_of' => $cat_ID );
		$categories = get_categories( $args );
	}
}







//lists all non-empty subcategories categories under main category
//posts appear under current subcategory, click on subcategory leads to archive of those posts
function first_subcat_redirect() {

	$currCat = get_the_category();
	$currCatID = $currCat[0]->cat_ID;
		
		if (isset($_GET['certclass'])) { 
			$parentid = '9'; 
		} else {
			$parentid = $currCat[0]->parent;
		}
		$args = array(
			'hide_empty' => $hide_empty,
			'parent' => $parentid,
			);	
		$catarray = get_categories($args);
		$link = get_category_link( $catarray[0]->cat_ID );
		wp_redirect( $link ); exit;
}

function get_post_by_title( $page_title ) {
    global $wpdb;
        $post = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='post'", $page_title ));
        if ( $post )
            return $post;

    return null;
}

//add js filter
add_action('template_redirect', 'custom_filter_js');
function custom_filter_js() {
$root = get_template_directory_uri();
   wp_register_script('filtering', $root.'/js/filter.js', array('jquery') );
   wp_enqueue_script('filtering');
}

//custom javascript that fires only on magic fields post pages should be added to the custom-mf-js file 
//in themes/academica/js/custom-mf-js.js
function custom_mf_js() {
$root = get_template_directory_uri();
   wp_register_script('hide_mf', $root.'/js/custom-mf-js.js', array('jquery') );
   wp_enqueue_script('hide_mf');
}

//use to fill in numbers between start and end date
//made for porjects filter to list years
function fill_numbers_between( $start, $end, $output = 'string' ) {
	if ( $output == 'array' ) {	
	$array = array();
		if ( $start < $end ) {
			while ( $start <= $end ) {
				$array[] = $start;
				$start++;
			}
		} else {
			while ( $start >= $end ) {
				$array[] = $start;
				$start--;
			}
		}
		return $array;
	} //end output array 
	else {	
		$string = '';
		if ( $start < $end ) {
			while ( $start <= $end ) {
				$string .= $start." ";
				$start++;
			}
		} else {
			while ( $start >= $end ) {
				$string .= $start." ";
				$start--;
			}
		}
		return $string;
	} //end output anything other than array (returns string)
}


// oldest: tells function what yr the oldest post on the page is in, if false, function does not consider posts on page and does not show "older" link in any case
// num_yrs: how many years to show
// fixed: if false, shows only up to the oldest yr;  if true, shows number of yrs set by 2nd parameter even if the yrs have no posts
// newest: pass a number to start the archive at if other than current yr.

function archive_filter( $oldest = false, $num_yrs = 5, $fixed = false, $newest = false )  {
	
	$span = $num_yrs;
	$end = date('Y'); //start from current year
	if ( $newest ) { $end = $newest; }
	$begin = $end - $span;

	if ( $oldest  && ( $oldest < $begin ) ) {
		$older ="
		<li><a class='show-older' name='".$begin."' title='Older'>Older</a></li>
		";
	}
	if ( ! $fixed && $oldest  && ( $oldest >= $begin ) ) {
		$begin = $oldest;
	}
	
	$return = "
	<div class='filter_wrap'>
		<span>Filter by year</span>
		<ol id='filter-by-year'>
			<li><a class='show-all current-yr' title='All'>All</a></li>
	"; 
	
	$numbers = fill_numbers_between( $end, $begin, 'array' );
	foreach ( $numbers as $number ) {
		$return .= "
		<li><a class='year' title='".$number."'>".$number."</a></li>
		";
	}
	$return .= $older;
	$return .= 
	"
	</ol></div>
    ";
	echo $return;
	return $begin;
}

function return_the_content($more_link_text = null, $stripteaser = 0) {
	$content = get_the_content($more_link_text, $stripteaser);
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]&gt;', $content);
	return $content;
}


class Custom_Walker extends Walker_Category {
 
function start_el(&$output, $category, $depth, $args) {
		extract($args);

		$cat_name = esc_attr( $category->name );
		$cat_name = apply_filters( 'list_cats', $cat_name, $category );
		$link = '<a href="' . esc_attr( get_term_link($category) ) . '" ';
		if ( $use_desc_for_title == 0 || empty($category->description) )
			$link .= 'title="' . esc_attr( sprintf(__( '%s' ), $cat_name) ) . '"';
		else
			$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
		$link .= '>';
		$link .= $cat_name . '</a>';

		if ( !empty($feed_image) || !empty($feed) ) {
			$link .= ' ';

			if ( empty($feed_image) )
				$link .= '(';

			$link .= '<a href="' . get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) . '"';

			if ( empty($feed) ) {
				$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
			} else {
				$title = ' title="' . $feed . '"';
				$alt = ' alt="' . $feed . '"';
				$name = $feed;
				$link .= $title;
			}

			$link .= '>';

			if ( empty($feed_image) )
				$link .= $name;
			else
				$link .= "<img src='$feed_image'$alt$title" . ' />';

			$link .= '</a>';

			if ( empty($feed_image) )
				$link .= ')';
		}

		if ( !empty($show_count) )
			$link .= ' (' . intval($category->count) . ')';

		if ( !empty($show_date) )
			$link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);

		if ( 'list' == $args['style'] ) {
			$output .= "\t<li";
			$class = 'cat-item cat-item-' . $category->term_id;
			if ( !empty($current_category) ) {
				$_current_category = get_term( $current_category, $category->taxonomy );
				if ( $category->term_id == $current_category )
					$class .=  ' current-cat';
				elseif ( $category->term_id == $_current_category->parent )
					$class .=  ' current-cat-parent';
			}
			$output .=  ' class="' . $class . '"';
			$output .= ">$link\n";
		} else {
			$output .= "\t$link<br />\n";
		}
	}

}

//functions for classes...semester start end end dates set in this file
//along with the class calendar functions
include(TEMPLATEPATH.'/class-related-functions.php');

require_once(TEMPLATEPATH.'/includes/widgets.php');


$functions_path = TEMPLATEPATH . '/admin/';
require_once ($functions_path . 'functions.php');
$homepath = get_bloginfo('stylesheet_directory');

add_action('admin_menu', 'proud_add_admin');
?>